package io.renren.modules.deliveryman.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.DateUtils;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.deliveryman.entity.DeliveryManEntity;
import io.renren.modules.deliveryman.service.DeliveryManService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 配送员信息
 *
 * @author cyx
 * @email 714529684@qq.com
 * @date 2022-02-22 22:24:36
 */
@RestController
@RequestMapping("generator/deliveryman")
public class DeliveryManController {
    @Autowired
    private DeliveryManService deliveryManService;

    /**
     * 获取所有
     */
    @RequestMapping("/getAll")
    public R list(){
        List<DeliveryManEntity> list = deliveryManService.list();

        return R.ok().put("list", list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:deliveryman:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = deliveryManService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:deliveryman:info")
    public R info(@PathVariable("id") Long id){
		DeliveryManEntity deliveryMan = deliveryManService.getById(id);

        return R.ok().put("deliveryMan", deliveryMan);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:deliveryman:save")
    public R save(@RequestBody DeliveryManEntity deliveryMan){
        deliveryMan.setCreateby(((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername());
        deliveryMan.setCreatetime(new Date());
		deliveryManService.save(deliveryMan);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:deliveryman:update")
    public R update(@RequestBody DeliveryManEntity deliveryMan){
        deliveryMan.setUpdateby(((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername());
        deliveryMan.setUpdatetime(new Date());
		deliveryManService.updateById(deliveryMan);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:deliveryman:delete")
    public R delete(@RequestBody Long[] ids){
		deliveryManService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
